Euler Problem 39

If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p ≤ 1000, is the number of solutions maximised?


In [1]:
from math import gcd
from collections import Counter

count = Counter()

for m in range(2, 1000):
    for n in range(1 + (m % 2), m, 2):
        if gcd(m, n) == 1:
            p = 2 * m * (m + n)
            if p > 1000:
                break
            count.update(range(p, 1001, p))

print(count.most_common(1)[0][0])


840

In [ ]: